<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('订单主子表详情界面')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form id="form-edit" class="form-horizontal">
            <h4 class="form-header h4">订购单信息</h4>
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">订单编号：</label>
                        <div class="col-sm-8">
                            <input name="orderIndent" id="orderIndent" class="form-control" th:value="${order2.orderIndent}" type="text" maxlength="30" disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">客户姓名：</label>
                        <div class="col-sm-8" >
                            <input name="customerName" disabled th:value="${order2.customerName}" class="form-control" type="text" maxlength="30">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">订购时间：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="orderTime" class="form-control" placeholder="yyyy-MM-dd hh:mm:ss" disabled type="text" th:value="${#dates.format(order2.orderTime, 'yyyy-MM-dd hh:mm:ss')}">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">创建人：</label>
                        <div class="col-sm-8">
                            <input name="sysOperUserId" class="form-control" type="hidden"  th:value="${user.userId}">
                            <input name="" class="form-control"  type="text" disabled  th:value="${user.userName}">
                        </div>
                    </div>


            <div class="form-group">
                <label class="col-sm-4 control-label is-required">审核状态：</label>
                <div class="col-sm-8">
                    <input  value="未审核" disabled name="chkStatus"   th:if="${order2.chkStatus}==0"  class="form-control" type="text" maxlength="30" >
                    <input  value="审核中" disabled name="chkStatus"   th:if="${order2.chkStatus}==1"  class="form-control" type="text" maxlength="30" >
                    <input  value="审核通过" disabled name="chkStatus"   th:if="${order2.chkStatus}==2"  class="form-control" type="text" maxlength="30" >
                    <input  value="审核不通过" disabled name="chkStatus"   th:if="${order2.chkStatus}==3"  class="form-control" type="text" maxlength="30" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">总金额：</label>
                <div class="col-sm-8">
                    <input id="orderMoney" name="orderMoney" disabled th:value="${order2.orderMoney}" class="form-control" type="text" maxlength="11" readonly>
                </div>
            </div>

            <div class="form-group">
                        <label class="col-sm-4 control-label is-required">审核意见：</label>
                        <div class="col-sm-8">
                            <input id="opinion" name="opinion" disabled th:value="${order.opinion}" class="form-control" type="text" maxlength="11" readonly>
                        </div>
            </div>

            <div class="form-group">
                <label class="col-sm-4 control-label is-required">审核人：</label>
                <div class="col-sm-8">
                    <input id="sysChkUserId" name="sysChkUserId" disabled th:value="${order.sysChkUserId}" class="form-control" type="text" maxlength="11" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">审核时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="checkTime" class="form-control" placeholder="yyyy-MM-dd hh:mm:ss" disabled type="text" th:value="${#dates.format(order.checkTime, 'yyyy-MM-dd hh:mm:ss')}">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>

            <h4 class="form-header h4">商品数据</h4>
            <div class="row">
                <div class="col-sm-12">
<!--                    <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>-->
<!--                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>-->
<!--                    <button type="button" class="btn btn-white btn-sm"  id="totalMoeny" onclick="addMoney()"><i class="fa fa-plus"> 计算所有商品总金额</i></button>-->
                    <div class="col-sm-12 select-table table-striped" >
					    <table id="bootstrap-table" onkeyup="foo()" >

                        </table>
					</div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:src="@{/js/jquery.tmpl.js}"></script>
	<script th:inline="javascript">

        $(function() {
            // "[{"num":1,"poBrandId":3,"poTypeId":1,"price":111.0,"productModel":"苹果13","total":111.0,"unit":"台"}]"

         /*   var data1 = [
                {
                    poBrandId: "2",
                    poTypeId: "1",
                    productModel: "苹果13",
                    num: "1",
                    unit: "台",
                    price: "2",
                    total:     "2",
                }];*/

            let data1 ='[[${poProduct2List}]]'.replace(/^\"|\"$/g,'');
            console.log('[[${poProduct2List}]]');
            console.log(typeof data1);
            console.log("parseJSON:"+jQuery.parseJSON(data1));
            var options = {
                data: jQuery.parseJSON(data1),
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'index',
                        align: 'center',
                        title: "序号",
                        formatter: function (value, row, index) {
                            var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                            var columnId = $.common.sprintf("<input type='hidden' name='' id='mkOrderIndent' value='%s'>", index, row.id);
                            return columnIndex + $.table.serialNumber(index) + columnId;
                        }
                    },
                    {
                        field: 'poBrandId',
                        align: 'center',
                        title: '品牌',
                        formatter: function(value, row, index) {
                            var data = [{ index: index, poBrandId: value }];
                            return $("#goodsTypeTpl1").tmpl(data).html();
                        }
                    },
                    {
                        field: 'poTypeId',
                        align: 'center',
                        title: '类型',
                        formatter: function(value, row, index) {
                            var data = [{ index: index, poTypeId: value }];
                            return $("#goodsTypeTpl2").tmpl(data).html();
                        }
                    },
                    {
                        field: 'productModel',
                        align: 'center',
                        title: '型号',
                        formatter: function(value, row, index) {
                            var data = [{ index: index, productModel: value }];
                            return $("#goodsTypeTpl3").tmpl(data).html();
                        }
                    },
                    {
                        field: 'num',
                        align: 'center',
                        title: '数量',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' disabled type='text' id='num' name='poProduct2List[%s].num' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'unit',
                        align: 'center',
                        title: '单位',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' disabled type='text' name='poProduct2List[%s].unit' value='台' >", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'price',
                        align: 'center',
                        title: '商品价格',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control price' disabled type='text' id='price'  name='poProduct2List[%s].price' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'total',
                        align: 'center',
                        title: '金额',
                        formatter: function (value, row, index) {
                            var html = $.common.sprintf("<input class='form-control money' disabled type='text' readonly id='money' name='poProduct2List[%s].total' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                    field: 'detailId',
                    align: 'center',
                    // title: '订单详情id',
                    formatter: function (value, row, index) {
                    var html = $.common.sprintf("<input class='form-control money' type='hidden' disabled id='detailId' name='poProduct2List[%s].detailId' value='%s'>", index, value);
                    return html;
            }}
        ]
            };
            $.table.init(options);
        });


        var prefix = ctx + "market/order"
        $("#form-edit").validate({
            focusCleanup: true
        });

        // function submitHandler() {
        //     if ($.validate.form()) {
        //         // alert($('#form-edit').serialize());
        //         $.operate.save(prefix + "/edit", $('#form-edit').serialize());
        //     }
        // }

        function addColumn() {
        	var row = {
                poBrandId: "",
                poTypeId: "",
                productModel: "",
                num: "",
                unit: "",
                price: "",
                total: "",
                detailId:""
            }
        	sub.addColumn(row);
        }

        function foo(e) {
            e = e || window.event;
            var el = e.Target || e.srcElement
            while(el.nodeName != 'TR') el = el.parentNode;
            var o = el.getElementsByTagName('input');
            o[6].value = o[3].value * o[5].value;//计算单行金额
            $("#orderMoney").val(o[6].value);//赋值给上面主表的总金额

        }
        function addMoney() {
            var array = {};//定义一个数组
            var array = document.getElementsByClassName('money');
            var total = 0;
            for(j = 0,len=array.length; j < len; j++) {
                total = parseInt(array[j].value) + total;
            }
            document.getElementsByName("orderMoney")[0].value=total;
        }
    </script>

</body>
</html>
<!-- 品牌 -->
<script id="goodsTypeTpl1" type="text/x-jquery-tmpl">
<div th:each="p : ${poProductList}">
<select class='form-control' disabled name='poProduct2List[${index}].poBrandId' >
                <option value="">请选择</option>
                <option value="3" th:selected="${p.poBrandId}==3">海尔1</option>
                <option value="4" th:selected="${p.poBrandId}==4">联想</option>
                <option value="11" th:selected="${p.poBrandId}==11">联想1</option>
</select>
</div>
</script>

<!-- 类型 -->
<script id="goodsTypeTpl2" type="text/x-jquery-tmpl">
<div th:each="p : ${poProductList}">
<select class='form-control' disabled name='poProduct2List[${index}].poTypeId'>
                <option  value="">请选择</option>
                <option  value="1" th:selected="${p.poTypeId}==1">笔记本电脑</option>
                <option  value="2" th:selected="${p.poTypeId}==2">台式电脑</option>
                <option  value="3" th:selected="${p.poTypeId}==3">手机</option>
</select>
</div>
</script>
<!-- 型号 -->
<script id="goodsTypeTpl3" type="text/x-jquery-tmpl">
<div th:each="p : ${poProductList}">
<select class='form-control' disabled name='poProduct2List[${index}].productModel'>
                <option value="">请选择</option>
                <option value="苹果13" th:selected="${p.productModel} eq '苹果13'">苹果13</option>
                <option value="拯救者y7000" th:selected="${p.productModel} eq '拯救者y7000'">拯救者y7000</option>
                <option value="小米144寸臻享版平板" th:selected="${p.productModel} eq '小米144寸臻享版平板'">小米144寸臻享版平板</option>
</select>
</div>
</script>